//
//  SYDMineCenterView.m
//  PinGJByOwnerSide
//
//  Created by lantaiyuan on 2017/8/8.
//  Copyright © 2017年 lantaiyuan. All rights reserved.
//

#import "SYDMineCenterView.h"
@interface SYDMineCenterView()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headerConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *userViewTopConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftTopConstraint;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *statusBtnWidthConstraint;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *userIconImageView;
@property (weak, nonatomic) IBOutlet UILabel *userNameLbl;
@property (weak, nonatomic) IBOutlet UIView *userIconView;
@property (weak, nonatomic) IBOutlet UIButton *userStatusBtn;
@end
@implementation SYDMineCenterView

- (void)awakeFromNib{
    [super awakeFromNib];
    if (iPhone8_X) {
        self.leftTopConstraint.constant = 55;
        self.userViewTopConstraint.constant = 89;
        self.headerConstraint.constant = 161;
    } else {
        self.leftTopConstraint.constant = 20;
        self.userViewTopConstraint.constant = 65;
        self.headerConstraint.constant = 139;
    }
    [self.userView drawBorderWithCornerRadius:5];
    [self.userStatusBtn drawBorderWithColor:GREEN_COLOR radius:self.userStatusBtn.height/2.0];
    self.userIconImageView.layer.cornerRadius = 27.5;
    self.userIconImageView.layer.masksToBounds = YES;
    self.userIconView.layer.cornerRadius = 31;
    self.userIconView.layer.masksToBounds = YES;
}

-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (void)setTitle:(NSString *)title{
    _title = title;
    _titleLabel.text = title;
}
-(void)setUserIcon:(NSString *)userIcon{
    _userIcon = userIcon;
    [_userIconImageView sd_setImageWithURL:[NSURL URLWithString:userIcon] placeholderImage:[UIImage imageNamed:@"icon_head_portrait1"]];
}
-(void)setUserName:(NSString *)userName{
    _userName = userName;
    _userNameLbl.text = userName;
}
-(void)setUserStatus:(NSString *)userStatus{
    _userStatus = userStatus;
    [_userStatusBtn setTitle:userStatus forState:UIControlStateNormal];
    
    _statusBtnWidthConstraint.constant = [NSString boundingRectWithString:_userStatus font:_userStatusBtn.titleLabel.font height:_userStatusBtn.height].width + 10;
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([SYDMineCenterView class]) owner:nil options:nil].lastObject;
        self.frame = frame;
    }
    return self;
}

- (void)setRightView:(UIView *)rightView{
    _rightView = rightView;
}

- (void)setLeftView:(UIView *)leftView{
    _leftView = leftView;
}

- (void)setTitleView:(UIView *)titleView{
    _titleView = titleView;
}
-(void)setHeaderView:(UIView *)headerView{
    _headerView = headerView;
}

-(void)setUserView:(UIView *)userView{
    _userView =  userView;
}
- (void)hiddenAllSubviews{
    _leftView.hidden = YES;
    _rightView.hidden = YES;
    _titleView.hidden = YES;
    _headerView.hidden = YES;
    _userView.hidden = YES;
}

@end


